<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>积分详情</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/font-awesome.min93e3.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/css/style.min.css"/>
<style type="text/css">
body{font-size: 14px;padding: 10px;}
#condition div.row{margin-bottom: 20px;}
.dataTables_info {font-size: 12px}
.dataTables_paginate {font-size: 12px;}
</style>
</head>
<body class="gray-bg">
	<div class="container-fluid">
		<div id="condition" style="background-color: white;padding: 20px;line-height: 34px;">
			<form action="">
				<div class="row">
<!-- 					<div class="col-sm-1 text-right"> -->
<!-- 						会员昵称 -->
<!-- 					</div> -->
<!-- 					<div class="col-sm-2"> -->
<!-- 						<input id="name" class="form-control"> -->
<!-- 					</div> -->
					<div class="col-sm-1 text-right">
						手机号
					</div>
					<div class="col-sm-2">
						<input id="phone" class="form-control">
					</div>
					<div class="col-sm-1 text-right">
						修改人
					</div>
					<div class="col-sm-2">
						<input id="modifier" class="form-control">
					</div>
					<div class="col-sm-1 text-right">
						积分变动
					</div>
					<div class="col-sm-2">
						<input id="integral1" class="form-control" style="display: inline-block;width: 70px;">至
						<input id="integral2" class="form-control" style="display: inline-block;width: 70px;">
					</div>
					<div class="col-sm-1 text-right">
						变动方式
					</div>
					<div class="col-sm-2">
						<select id="gain_type" class="form-control">
							<option value="">不限</option>
							<option value="1">自动</option>
							<option value="2">手动</option>
						</select>
					</div>
				</div>
				<div class="row">
					<div class="col-sm-1 text-right">
						变更途径
					</div>
					<div class="col-sm-2">
						<select id="gain_way" class="form-control">
							<option value="">不限</option>
							<option value="1">手动增加</option>
							<option value="2">订单增加</option>
							<option value="3">手动减少</option>
						</select>
					</div>
				</div>
				<div class="row text-center">
					<button onclick="func_search()" class="btn btn-primary" type="button">查询</button>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			        <button onclick="func_reset()" class="btn btn-white" type="button" style="border-color: #18a689;">重置</button>
				</div>
			</form>
		</div>
		<div style="background-color: white;margin: 20px 0;padding: 20px 20px 0;">
			<div class="row">
				<div class="col-sm-12">
					<table id="myTable" class="display">
						<thead>
							<tr>
								<th>序号</th>
								<th>手机号码</th>
				                <th>修改时间</th>
				                <th>修改人</th>
				                <th>积分变动</th>
				                <th>获取方式</th>
				                <th>积分变更途径</th>
				                <th>修改原因</th>
							</tr>
						</thead>
					</table>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/bootcdn/BootCDN/ajax/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
<script type="text/javascript">
var path = "<%=path%>";
var myDataTable;
var dataTable_index = 1;

$(function(){
	init();
});

function init(){
	myDataTable = dataTable();
}

//查询
function func_search(){
	func_dataTableReload();
}

//查询条件重置
function func_reset(){
	$("#condition form")[0].reset();
	func_dataTableReload();
}

function func_dataTableReload(resetPaging) {
	if(resetPaging != undefined){
	    myDataTable.ajax.reload(null,resetPaging);
	}else{
		myDataTable.ajax.reload();
		dataTable_index = 1;
	}
}

function func_AjaxUrl() {
    return path + "/scan/integral/getPage";
}

function func_columns() {
    var jsonArr = [
    	{"data": "id"},
        {"data": "phone"},
        {"data": "create_time"},
        {"data": "modifier"},
        {"data": "integral"},
        {"data": "gain_type"},
        {"data": "gain_way"},
        {"data": "gain_reason"}
    ];
    return jsonArr;
}

function func_ajaxData() {
    var jsonObject = new Object();
    
    if($.trim($("#name").val()) != ""){
	    jsonObject.name = $.trim($("#name").val());
    }
    if($.trim($("#phone").val()) != ""){
	    jsonObject.phone = $.trim($("#phone").val());
    }
    if($.trim($("#modifier").val()) != ""){
	    jsonObject.modifier = $.trim($("#modifier").val());
    }
    if($.trim($("#integral1").val()) != ""){
	    jsonObject.integral1 = $.trim($("#integral1").val());
    }
    if($.trim($("#integral2").val()) != ""){
	    jsonObject.integral2 = $.trim($("#integral2").val());
    }
    if($("#gain_type").val() != ""){
	    jsonObject.gain_type = $("#gain_type").val();	//积分变动方式
    }
    if($("#gain_way").val() != ""){
	    jsonObject.gain_way = $("#gain_way").val();	//积分变更途径
    }
    return jsonObject;
}

function dataTable() {
    return $('#myTable').DataTable({
        processing: true,
        ordering: false,
        searching: false,
        info: true,
        autoWidth: true,
        lengthChange: false,
        language: {
            emptyTable: '没有数据表',
            info: '从第 _START_ 到第 _END_ 条数据；总共有 _TOTAL_ 条记录',
            infoEmpty: '没有数据',
            lengthMenu: '每页显示 _MENU_ 条记录',
            loadingRecords: '正在加载数据....',
            processing: '正在处理数据....',
            zeroRecords: '没有找到匹配的记录',
            paginate: {
                first: '首页',
                previous: '前页',
                next: '后页',
                last: '尾页'
            }
        },
        order: [[1, 'desc']],
        pageLength: 10,
        pagingType: 'full_numbers',
        columnDefs: [{
            render: function (data, type, full) {
                var result = dataTable_index++;
                return result;
            },
            targets: 0
        },{
            render: function (data, type, full) {
                var result = "";
                var d = new Date(data);
            	result = d.format("yyyy-MM-dd hh:mm");
                return result;
            },
            targets: 2
        },{
            render: function (data, type, full) {	//积分获取方式。1：自动；2：手动
                var result = "";
				if(data == 1){
	            	result = "自动";
				}else if(data == 2){
	            	result = "手动";
				}
                return result;
            },
            targets: 5
        },{
            render: function (data, type, full) {	//积分获取途径。1：手动增加；2：订单增加；3：手动减少
                var result = "";
                if(data == 1){
	            	result = "手动添加";
				}else if(data == 2){
	            	result = "订单增加";
				}else if(data == 3){
	            	result = "手动减少";
				}
                return result;
            },
            targets: 6
        }],
        columns: func_columns(),
        serverSide: true,
        ajax: {
            contentType: 'text/plain;charset=utf-8',
            type: 'POST',
            url: func_AjaxUrl(),
            data: function (d) {
                d.extra_search = func_ajaxData();
                return JSON.stringify(d);
            }
        }
	});
}

function getUrlParam(key){
	var reg = new RegExp("(^|&)"+ key +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}

Date.prototype.format = function(fmt) { 
    var o = { 
       "M+" : this.getMonth()+1,                 //月份 
       "d+" : this.getDate(),                    //日 
       "h+" : this.getHours(),                   //小时 
       "m+" : this.getMinutes(),                 //分 
       "s+" : this.getSeconds(),                 //秒 
       "q+" : Math.floor((this.getMonth()+3)/3),
       "S"  : this.getMilliseconds()             //毫秒 
   }; 
   if(/(y+)/.test(fmt)) {
           fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); 
   }
    for(var k in o) {
       if(new RegExp("("+ k +")").test(fmt)){
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        }
    }
   return fmt; 
}
</script>
</html>